package com.lzh.file.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lzh.runke.core.entity.BaseEntity;
import com.lzh.runke.core.web_base.constant.DateConstant;
import com.lzh.runke.core.web_base.constant.StringConstant;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 文件信息
 *
 * @author linmeijie
 */
@Getter
@Setter
@SuperBuilder
public class FileInfo extends BaseEntity {

    private static final long serialVersionUID = -7352349203687471799L;

    /**
     * 保存的文件名
     */
    protected String filename;

    /**
     * 原始文件名
     */
    protected String originalName;

    /**
     * 文件上传时间
     */
    @JsonFormat(pattern = DateConstant.FMT_YMDHMS)
    protected Date uploadDate;

    /**
     * 文件大小/ byte
     */
    protected long fileSize;

    /**
     * 是否已与业务表关联
     * 0: 未关联
     * 1：已关联
     */
    protected Boolean relatedFlag = false;

    /**
     * 会话ID，用于下载用户校验
     */
    private String username;

    public FileInfo() { }

    public FileInfo(String filename) {
        this.filename = filename;
        if (StringUtils.isNotBlank(filename)) {
            this.id = StringUtils.substringBefore(filename, StringConstant.DOT);
        }
    }
}
